package org.dreamwork.jasmine2.parser;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 2010-9-20
 * Time: 17:23:28
 */
public class JavaCodeFormat {
    public static String convert (String text) {
        StringBuilder builder = new StringBuilder ();
        for (int ch : text.toCharArray ()) {
            switch (ch) {
                case '"'  :
                    builder.append ("\\\"");
                    break;
                case '\\' :
                    builder.append ("\\\\");
                    break;
                case '\t' :
                    builder.append ("\\t");
                    break;
                case '\n' :
                    builder.append ("\\n");
                    break;
                case '\r' :
                    builder.append ("\\r");
                    break;
                default :
                    builder.append ((char) ch);
                    break;
            }
        }
        return builder.toString ();
    }
}